In [ ]:
# identify this trial
x = gaze_df.loc[(gaze_df.Subject == 1) & (gaze_df.Day == 1) & (gaze_df.Trial == 1)].fixOn
width = gaze_df.loc[(gaze_df.Subject == 1) & (gaze_df.Day == 1) & (gaze_df.Trial == 1)].fixLen
bottom = gaze_df.loc[(gaze_df.Subject == 1) & (gaze_df.Day == 1) & (gaze_df.Trial == 1)].catCode
# order by position
# bottom = gaze_df.loc[(gaze_df.Subject == 1) & (gaze_df.Day == 1) & (gaze_df.Trial == 1)].Position
height = [0.5] * len(x)
labels = list(string.ascii_uppercase[0:4])

In [ ]:
plt.bar(x, height, width, bottom, align='edge', fill=False)
plt.xlabel('Time (s)')
plt.ylabel('Target')
ax=plt.gca()                            # get the axis
ax.set_ylim(ax.get_ylim()[::-1])        # invert the axis
ax.yaxis.set_ticks([1.25,2.25,3.25,4.25]) # set y-ticks
ax.yaxis.tick_left()                    # remove right y-Ticks
ax.set_yticklabels(labels, fontdict=None, minor=False)

for spine in plt.gca().spines.values():
    spine.set_visible(False)

# remove all the ticks and directly label each bar with respective value
plt.tick_params(top='off', bottom='off', left='off', right='off', labelbottom='on')

plot all trials for all days for one subject


In [ ]:
# plotGazeTimeline(gaze_df, 1, 1, 2, 1)
width = 8
height = 12
fig, ax = plt.subplots(nrows=10, ncols=3, sharex=True, sharey=True, figsize=(width, height))

sbj = 1
figName = '/Users/jc/Documents/GitHub/shootGaze/figs/s' + str(sbj) + 'gaze.png'

for dy in range(1,4):
    for tr in range(1,11):
        plotGazeTimeline(gaze_df, sbj, dy, tr, ax)

ax[0, 0].set_title('Day 1')
ax[0, 1].set_title('Day 2')
ax[0, 2].set_title('Day 3')
ax[9, 0].set_xlabel('Time (s)')
ax[9, 1].set_xlabel('Time (s)')
ax[9, 2].set_xlabel('Time (s)')

patch1 = mpatches.Patch(color='#d7191c', label='A')
patch2 = mpatches.Patch(color='#fdae61', label='B')
patch3 = mpatches.Patch(color='#abdda4', label='C')
patch4 = mpatches.Patch(color='#2b83ba', label='D')

plt.legend(handles=[patch1,patch2,patch3,patch4],
           bbox_to_anchor=(0.95, 0.95),
           loc=1, ncol=4,
           bbox_transform=plt.gcf().transFigure,
           fontsize=8)

# # Fine-tune figure; hide x ticks for top plots and y ticks for right plots
#plt.setp([a.get_xticklabels() for a in ax[0, :]], visible=False)
#plt.setp([a.get_yticklabels() for a in ax[:, 1]], visible=False)

# Tight layout often produces nice results but requires the title to be spaced accordingly
fig.tight_layout()
fig.subplots_adjust(top=0.88)

plt.savefig(figName)
# plt.show()
plt.close(fig)